package com.naiterui.ehp.bs.im.service.message.push;

import org.springframework.stereotype.Service;

import com.naiterui.ehp.bs.im.network.protocl.Shield;
import com.naiterui.ehp.bs.im.repository.mongo.ShieldDao;
import com.naiterui.ehp.bs.im.vo.ShieldVO;

@Service
public class ShieldHandler {

    /**
     * 1，打开勿扰模式
     */
    private static final int SHIELD_ON = 1;

    private final ShieldDao shieldDao;

    public ShieldHandler(ShieldDao shieldDao) {
        this.shieldDao = shieldDao;
    }

    /**
     * 设置对当前病人屏蔽,或者
     */
    public void setShield(Shield shield, int operate) {
        if (operate == SHIELD_ON) {
            shieldDao.saveShield(shield);
        } else {
            shieldDao.removeShield(shield.getUserId(), shield.getShieldId());
        }
    }

    /**
     * 获取医生屏蔽的病人列表
     */
    public ShieldVO getShield(Long userId) {
        return shieldDao.findShieldList(userId);
    }

    /**
     * 当前用户是否对该病人开启了消息屏蔽
     */
    public boolean isShield(Long userId, Long shieldId) {
        if (shieldDao.findShield(userId, shieldId) != null) {
            return true;
        }
        return false;
    }

}
